import { Http } from '@/utils';
import EntityServie from '@/service/entity-service';

/**
 * 账户服务对象
 *
 * @export
 * @class AccountService
 * @extends {EntityServie}
 */
export default class AccountService extends EntityServie {

    /**
     * Creates an instance of  AccountService.
     * 
     * @param {*} [opts={}]
     * @memberof  AccountService
     */
    constructor(opts: any = {}) {
        super(opts);
    }

    /**
     * Save
     *
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof AccountService
     */
    public save(data: any = {}, isloading?: boolean): Promise<any> {
        let purview: string = '';
        if (this.getStore()) {
            const localdata: any = this.getStore().getters.getLocalData();
            const { pk1, pk2, pk3 }: { pk1: string, pk2: string, pk3: string } = localdata;
            purview = `${pk1}/${pk2}/${pk3}/`;
        }
        return Http.getInstance().put(`${purview}v7/account/${data.srfkey}`, data, isloading);
    }

    /**
     * Remove
     *
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof AccountService
     */
    public remove(data: any = {}, isloading?: boolean): Promise<any> {
        let purview: string = '';
        if (this.getStore()) {
            const localdata: any = this.getStore().getters.getLocalData();
            const { pk1, pk2, pk3 }: { pk1: string, pk2: string, pk3: string } = localdata;
            purview = `${pk1}/${pk2}/${pk3}/`;
        }
        let url: string = 'v7/account/';
        if (data.srfkeys && !Object.is(data.srfkeys, '')) {
            url = `${url}${data.srfkeys}`;
        } else if (data.srfkey && !Object.is(data.srfkey, '')) {
            url = `${url}${data.srfkey}`;
        }
        return Http.getInstance().delete(`${purview}${url}`, isloading);
    }

    /**
     * Update
     *
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof AccountService
     */
    public update(data: any = {}, isloading?: boolean): Promise<any> {
        let purview: string = '';
        if (this.getStore()) {
            const localdata: any = this.getStore().getters.getLocalData();
            const { pk1, pk2, pk3 }: { pk1: string, pk2: string, pk3: string } = localdata;
            purview = `${pk1}/${pk2}/${pk3}/`;
        }
        return Http.getInstance().put(`${purview}v7/account/${data.srfkey}`, data, isloading);
    }

    /**
     * CheckKey
     *
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof AccountService
     */
    public checkkey(data: any = {}, isloading?: boolean): Promise<any> {
        let purview: string = '';
        if (this.getStore()) {
            const localdata: any = this.getStore().getters.getLocalData();
            const { pk1, pk2, pk3 }: { pk1: string, pk2: string, pk3: string } = localdata;
            purview = `${pk1}/${pk2}/${pk3}/`;
        }
        return Http.getInstance().post('', data, isloading);
    }

    /**
     * Create
     *
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof AccountService
     */
    public create(data: any = {}, isloading?: boolean): Promise<any> {
        let purview: string = '';
        if (this.getStore()) {
            const localdata: any = this.getStore().getters.getLocalData();
            const { pk1, pk2, pk3 }: { pk1: string, pk2: string, pk3: string } = localdata;
            purview = `${pk1}/${pk2}/${pk3}/`;
        }
        return Http.getInstance().post(`${purview}v7/account`, data, isloading);
    }

    /**
     * Get
     *
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof AccountService
     */
    public get(data: any = {}, isloading?: boolean): Promise<any> {
        let purview: string = '';
        if (this.getStore()) {
            const localdata: any = this.getStore().getters.getLocalData();
            const { pk1, pk2, pk3 }: { pk1: string, pk2: string, pk3: string } = localdata;
            purview = `${pk1}/${pk2}/${pk3}/`;
        }
        let url: string = 'v7/account';
        if (data.srfkey && !Object.is(data.srfkey, '')) {
            url = `${url}/${data.srfkey}`;
            data = {};
        }
        return Http.getInstance().get(`${purview}${url}`, data, isloading);
    }

    /**
     * GetDraft
     *
     * @param {*} [data={}]
     * @param {boolean} [isloading]
     * @returns {Promise<any>}
     * @memberof AccountService
     */
    public getdraft(data: any = {}, isloading?: boolean): Promise<any> {
        let purview: string = '';
        if (this.getStore()) {
            const localdata: any = this.getStore().getters.getLocalData();
            const { pk1, pk2, pk3 }: { pk1: string, pk2: string, pk3: string } = localdata;
            purview = `${pk1}/${pk2}/${pk3}/`;
        }
        return Http.getInstance().post(`${purview}v7/loaddraft/account`, data, isloading);
    }

//工作流相关


}